package gatperdut.chato.core.room;

import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.interpreter.grammar.comminfo.indexedword.IndexedWord;

import java.util.ArrayList;
import java.util.List;

public class CharactersController {

    private final List<BaseController> baseControllers = new ArrayList<BaseController>();

    public BaseController getEntityController( IndexedWord iw ) {
        int matches = 0;

        for ( BaseController bc : getBaseControllers() ) {
            if ( bc.getKeywordsController().matchesKeyword( iw.getWord() ) ) {
                matches++;
                if ( matches == iw.getIndex() ) {
                    return bc;
                }
            }
        }

        return null;
    }

    public void enterRoom( BaseController baseController ) {
        getBaseControllers().add( baseController );
    }

    public void leaveRoom( BaseController baseController ) {
        getBaseControllers().remove( baseController );
    }

    public List<BaseController> getBaseControllers() {
        return baseControllers;
    }
}
